﻿using DMSkin.Core;
using Dt261.ble;
using Dt261.ViewModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
//using InTheHand.Bluetooth;
using Windows.Devices.Bluetooth;
using Windows.Devices.Bluetooth.GenericAttributeProfile;
using Windows.Devices.Enumeration;
using Windows.Foundation;
using Windows.Security.Cryptography;
//using BluetoothDevice = InTheHand.Bluetooth.BluetoothDevice;

namespace Dt261.Views
{
    /// <summary>
    /// LoginWindow.xaml 的交互逻辑
    /// </summary>
    public partial class LoginWindow : Window
    {
        BleCore bluetooth;
        //  private DeviceWatcher deviceWatcher;
        public LoginWindow()
        {
            InitializeComponent();

            Broadcast.RegisterBroadcast<string>("LoginOK", (obj) =>
            {
                DialogResult = true;
            });

         


            this.DataContext = new LoginWindowViewModel();
        }

        public void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Hyperlink_Click(object sender, RoutedEventArgs e)
        {

        }



        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //logger.Info("日志-start Button_Click_1" + sender.ToString()); // 何时输出日志
            if (new RegisterWindow().ShowDialog() == true)
            {


                //   new MainWindow().ShowDialog();
            }
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            //new Views.WindowX().ShowDialog();
        }


        //public  void eventRun(MsgType type, string str, byte[] data = null)
        //{
        //    Console.WriteLine(data);
        //    Console.WriteLine(str);


        //}

        //private void Button_Click(object sender, RoutedEventArgs e)
        //{
        //    DialogResult = true;



        //    //            00001800 - 0000 - 1000 - 8000 - 00805f9b34fb
        //    //00001801 - 0000 - 1000 - 8000 - 00805f9b34fb
        //    //0000180a - 0000 - 1000 - 8000 - 00805f9b34fb
        //    //0000ff12 - 0000 - 1000 - 8000 - 00805f9b34fb


        //    //{ 0000ff01 - 0000 - 1000 - 8000 - 00805f9b34fb}
        //    //bluetooth = BleCore.shareInstance();// new BleCore("0000ff12-0000-1000-8000-00805f9b34fb", "0000ff01-0000-1000-8000-00805f9b34fb", "0000ff02-0000-1000-8000-00805f9b34fb");
        //    //bluetooth.ValueChanged += eventRun;
        //    //bluetooth.StartBleDeviceWatcher();
        //    // Bluetooth bl = new Bluetooth();

        //    //  Task<bool> isopen = Bluetooth.GetAvailabilityAsync();
        //    //  Console.WriteLine(isopen.Result.ToString());


        //    //Task<IReadOnlyCollection<BluetoothDevice>> tt = Bluetooth.GetPairedDevicesAsync();

        //    // Console.WriteLine(tt.Result);



        //    //BluetoothLEScanOptions options = new BluetoothLEScanOptions();
        //    //options.AcceptAllAdvertisements = true;
        //    //Task<BluetoothLEScan> task = Bluetooth.RequestLEScanAsync(options);

        //    //Console.WriteLine(task.Status);

        //    //Task.WhenAll(task).ContinueWith((t) => {

        //    //    Console.WriteLine("执行后续操作完毕！");
        //    //    Console.WriteLine(task.Result);
        //    //});

        //    //Task<BluetoothDevice> task2 = Bluetooth.RequestDeviceAsync();

        //    //Console.WriteLine(task2.Status);



        //    //Console.WriteLine(task.Result.ToString());
        //    // bluetooth = new BleCore();
        //    // bluetooth.StartBleDeviceWatcher();



        //}

        //private void Button_Click_1(object sender, RoutedEventArgs e)
        //{
        //    bluetooth.SelectDeviceFromIdAsync("f4:84:4c:46:23:db");

        //    //GetDeviceSelectorFromDeviceName
        //}

        /**
       *  [How to check if bluetooth is enabled on a device](https://stackoverflow.com/a/48794678)
       * *
        public bool GetBluetoothIsEnable()
        {
            SelectQuery sq = new SelectQuery("SELECT DeviceId FROM Win32_PnPEntity WHERE service='BthLEEnum'");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(sq);
            return searcher.Get().Count > 0;
        }*/
    }

}
